/**
 * 济南市政府采购网爬虫
 *  
 */
import {Base,Item} from '../base';
class cdcg extends Base{
    document:Document;
    constructor(){
        super();
        this.name = "济南市政府采购网";
        this.enabled = true;
        this.encode = 'gb2312';
        this.debug = false;
        this.timeout = 1000000;
        this.collection = "ztb";
        this.collectionShowName = "招投标信息";
        this.keyField = "title";
    }
    getItems(pageIndex:number):Item[]{
        let num =pageIndex+1;
        let url=`http://www.ccgp-jinan.gov.cn/jngp/site/list.jsp?curpage=${num}&colid=121`;
        let result :Item[]= [];
        let content=this.spider.getSync(url);
        let $=this.cheerio.load(content);
        let that =this;
        $('#table14 table').eq(0).find('tr').each(function(index,ele){
            let item =that.buildItem();
            item.title=$(ele).find('td').eq(1).find('a').text().trim();
            item.source=that.name;
            (<any>item)['公告时间']=$(ele).find('td').eq(2).text().trim().substring(1,10);
            let uri='http://www.ccgp-jinan.gov.cn'+$(ele).find('td').eq(1).find('a').attr('href');
            (<any>item).url='http://www.ccgp-jinan.gov.cn'+$(ele).find('td').eq(1).find('a').attr('href');
            result=that.getExtraItem(uri,item,result);
        });
        return result;
    }
    getExtraItem(url:string, item:Item, result:Item[]) {
        let content = this.spider.getSync(url);
        let $ = this.cheerio.load(content);
        (<any>item).content =$('body table').eq(2).html();
        result.push(item);
        return result;
    }
    getPageCount() {
        return 20;
    }
}
module.exports=new cdcg();